package com.izerui.mapper;

import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface ThamsMapper {
	@Select("select * from s_qzh where qzh=#{qzh}")
	Map getQzByQzh(@Param("qzh") String qzh);
	
	@Select("select * from s_role where jsmc=#{jsmc}")
	Map getRoleByJsmc(@Param("jsmc") String jsmc);
	
	@Select("select MAX(DID) from S_QZH")
	Integer getMaxDIDForQzh();
	
	
	@Select("select MAX(DID) from S_ROLE")
	Integer getMaxDIDForRole();
	
	@Select("select MAX(DID) from S_GROUP")
	Integer getMaxDIDForGroup();
	
	@Select("select MAX(DID) from S_USER")
	Integer getMaxDIDForUser();
	
	@Select("select MAX(DID) from S_USERROLE")
	Integer getMaxDIDForUserRole();
	
	
	@Select("update s_qzh set qzmc = #{qzmc,jdbcType=VARCHAR} where qzh = #{qzh,jdbcType=VARCHAR}")
	void updateQzmc(@Param("qzh") String qzh,@Param("qzmc") String qzmc);
	
	
	
	/**
	 * 根据备注获取当前部门
	 * @param gname
	 * @return
	 */
	@Select("select * from s_group where bz = #{bz}")
	Map getGroupByBz(@Param("bz") String bz);
	
	/**
	 * 添加全宗
	 * @param map
	 */
	@Insert("insert into S_QZH(did,qzh,qzmc,isdef) values(#{map.DID,jdbcType=NUMERIC},#{map.QZH,jdbcType=VARCHAR},#{map.QZMC,jdbcType=VARCHAR},#{map.ISDEF,jdbcType=NUMERIC})")
	void insertQzh(@Param("map") Map map);
	
	/**
	 * 添加部门
	 * @param map
	 */
	@Insert("insert into S_GROUP(did,pid,qzh,gid,gname,bz) values(#{map.DID,jdbcType=NUMERIC},#{map.PID,jdbcType=NUMERIC},#{map.QZH,jdbcType=VARCHAR},#{map.GID,jdbcType=VARCHAR},#{map.GNAME,jdbcType=VARCHAR},#{map.BZ,jdbcType=VARCHAR})")
	void insertGroup(@Param("map") Map map);
	
	@Insert("insert into S_USER(did,pid,usercode,username,passwd) values (#{map.DID,jdbcType=NUMERIC},#{map.PID,jdbcType=NUMERIC},#{map.USERCODE,jdbcType=VARCHAR},#{map.USERNAME,jdbcType=VARCHAR},#{map.PASSWD,jdbcType=VARCHAR})")
	void insertUser(@Param("map") Map map);
	
	@Update("update S_USER set username = #{map.USERNAME,jdbcType=VARCHAR},passwd = #{map.PASSWD,jdbcType=VARCHAR} where usercode = #{map.USERCODE}")
	void updateUser(@Param("map") Map map);
	
	@Update("update s_user set pid = #{pid,jdbcType=NUMERIC} where usercode = #{usercode,jdbcType=VARCHAR}")
	void updateUserDept(@Param("pid") Integer pid,@Param("usercode") String usercode);
	
	@Update("update s_group set qzh = #{map.QZH,jdbcType=VARCHAR} , PID = #{map.PID,jdbcType=NUMERIC} , gname = #{map.GNAME,jdbcType=VARCHAR} where DID = #{map.DID,jdbcType=NUMERIC}")
	void updateGroupQzh(@Param("map") Map map);
	
	/**
	 * 根据用户代码获取当前用户
	 */
	@Select("select * from s_user where usercode = #{usercode}")
	Map getUserByUsercode(@Param("usercode") String usercode);
	
	/**
	 * 添加角色
	 * @param map
	 */
	@Insert("insert into s_role(did,jsmc,isxtmr) values (#{map.DID,jdbcType=NUMERIC},#{map.JSMC,jdbcType=VARCHAR},#{map.ISXTMR,jdbcType=NUMERIC})")
	void insertRole(@Param("map") Map map);
	
	@Insert("insert into s_userrole(did,yhid,jsid) values(#{map.DID,jdbcType=NUMERIC},#{map.YHID,jdbcType=NUMERIC},#{map.JSID,jdbcType=NUMERIC})")
	void insertUserRole(@Param("map") Map map);
	
	
}
